package com.laolang.pluto.framework.config.security.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.laolang.pluto.module.sys.entity.SysUser;
import java.util.Collection;
import java.util.Set;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @author laolang
 * @date 2021-08-07 00:14
 */
@NoArgsConstructor
@Data
public class LoginUser implements UserDetails {

    private static final long serialVersionUID = 1L;


    /**
     * token
     */
    private String token;

    /**
     * 用户名
     */
    private String username;

    /**
     * 登录ip
     */
    private String loginIp;

    /**
     * 登录时间
     */
    private Long loginTime;

    private Long expireTime;

    /**
     * 菜单列表
     */
    private Set<String> permissionList;

    private SysUser sysUser;


    public LoginUser(SysUser sysUser, Set<String> menuList) {
        this.sysUser = sysUser;
        this.permissionList = menuList;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }

    @Override
    public String getUsername() {
        return username;
    }

    /**
     * 是否未过期
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }


    /**
     * 是否未锁定
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 是否过期的用户凭证
     */
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用
     */
    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }
}
